package cn.itcast.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;

public class MyJdbcUtil {
	public static ComboPooledDataSource dataSource = new ComboPooledDataSource();

	public static boolean isMysql = false;
	
	public static boolean isSqlServer = false;
	
	public static boolean isOracleServer = false;
	
	public static boolean isPostgresServer = false;
	
	public static boolean isInformixServer = false;
	
	public static boolean isSybaseServer = false;
	
	static {
		isMysql = dataSource.getJdbcUrl().contains("mysql");
		isSqlServer = dataSource.getJdbcUrl().contains("sqlserver");
		isOracleServer = dataSource.getJdbcUrl().contains("oracle");
		isPostgresServer = dataSource.getJdbcUrl().contains("postgres");
		isInformixServer = dataSource.getJdbcUrl().contains("informix");
		isSybaseServer = dataSource.getJdbcUrl().contains("sybase");
	}

	public static DataSource getDataSource() {
		return dataSource;
	}

	public static Connection getConnection() throws SQLException {
		// System.out.println(dataSource.getConnection().getMetaData().getURL());
		return dataSource.getConnection();
	}
}
